#!/usr/bin/env python
# -*- coding:utf-8 -*-
# __author__ = winston

import tornado.ioloop
import tornado.options
import tornado.web
import tornado.httpserver
import sys
import os
from conf import conf
from core.my_log import logger
from tornado.httpclient import AsyncHTTPClient
from core.application import Application
from core.route import handlers
for h in handlers:
    logger.info(h.regex)

# 配置异步请求最大并发量
AsyncHTTPClient.configure(None,max_clients=1000)
# static_path = os.path.dirname(os.getcwd()) + "/007statics"

def main():
    # tornado.options.parse_command_line()
    try:
        port = conf.port
    except:
        port = 6506
    app = Application()
    app.listen(port)
    print("Starting development server:"+str(port))
    # http_server = tornado.httpserver.HTTPServer(app, xheaders=True)
    tornado.ioloop.IOLoop.instance().start()


def cpu_process():
    # tornado.options.parse_command_line()
    try:
        port = conf.port
    except:
        port = 6506
    app = Application()
    print("Starting development server:" + str(port))
    server = tornado.httpserver.HTTPServer(app)
    server.bind(port)
    server.start(0)  # forks one process per cpu
    tornado.ioloop.IOLoop.current().start()
    # server.listen(port, address="0.0.0.0")
    # tornado.ioloop.IOLoop.instance().start()

if __name__ == '__main__':
    main()

